package cn.chiship.framework.upms.biz.system.service.impl;

import cn.chiship.framework.upms.biz.system.entity.UpmsCategoryDict;
import cn.chiship.framework.upms.biz.system.entity.UpmsHelpContent;
import cn.chiship.framework.upms.biz.system.entity.UpmsHelpContentExample;
import cn.chiship.framework.upms.biz.system.mapper.UpmsCategoryDictMapper;
import cn.chiship.framework.upms.biz.system.mapper.UpmsHelpContentMapper;
import cn.chiship.framework.upms.biz.system.pojo.vo.ContentUnionAllCategoryVo;
import cn.chiship.framework.upms.biz.system.pojo.vo.UpmsHelpContentVo;
import cn.chiship.framework.upms.biz.system.service.UpmsHelpContentService;
import cn.chiship.sdk.core.base.BaseResult;
import cn.chiship.sdk.core.util.StringUtil;
import cn.chiship.sdk.framework.base.BaseServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * 帮助文档业务接口实现层
 * 2021/9/30
 *
 * @author lijian
 */
@Service
public class UpmsHelpContentServiceImpl extends BaseServiceImpl<UpmsHelpContent, UpmsHelpContentExample> implements UpmsHelpContentService {

    @Resource
    UpmsHelpContentMapper upmsHelpContentMapper;
    @Resource
    UpmsCategoryDictMapper upmsCategoryDictMapper;

    @Override
    public BaseResult selectDetailsByPrimaryKey(Object id) {
        UpmsHelpContentExample upmsHelpContentExample = new UpmsHelpContentExample();
        upmsHelpContentExample.createCriteria().andIdEqualTo(id.toString());
        List<UpmsHelpContent> upmsHelpContents = upmsHelpContentMapper.selectByExampleWithBLOBs(upmsHelpContentExample);
        if (upmsHelpContents.isEmpty()) {
            return null;
        }
        UpmsHelpContentVo helpContentVo = new UpmsHelpContentVo();
        BeanUtils.copyProperties(upmsHelpContents.get(0), helpContentVo);
        UpmsCategoryDict upmsCategoryDict = upmsCategoryDictMapper.selectByPrimaryKey(helpContentVo.getCategoryId());
        if (!StringUtil.isNull(upmsCategoryDict)) {
            helpContentVo.setCategoryName(upmsCategoryDict.getName());
        }
        return BaseResult.ok(helpContentVo);
    }

    @Override
    public List<ContentUnionAllCategoryVo> selectContentUnionAllCategory(HashMap<String, Object> map) {
        return upmsHelpContentMapper.selectContentUnionAllCategory(map);
    }
}
